//
//  CollectionViewCell.m
//  NineGroupProject
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "CollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "Masonry.h"
@implementation CollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    // 图片
    self.image_urlImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loading.jpg"]];
    self.image_urlImageView.frame = self.contentView.bounds;
    [self.contentView addSubview:self.image_urlImageView];
    self.image_urlImageView.backgroundColor = [UIColor redColor];
    self.image_urlImageView.userInteractionEnabled= YES;
    
    // 中文名
    self.name_zh_cnLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.name_zh_cnLabel];
    [self.name_zh_cnLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10 * WID);
        make.top.mas_equalTo(10 * HEI);
        make.width.mas_equalTo(self.image_urlImageView.frame.size.width);
        make.height.mas_equalTo(20 * HEI);
        
    }];
    self.name_zh_cnLabel.textColor = [UIColor whiteColor];
    self.name_zh_cnLabel.font = [UIFont systemFontOfSize:19];
    
    // 英文名
    self.name_enLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.name_enLabel];
    [self.name_enLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.name_zh_cnLabel);
        make.top.equalTo(self.name_zh_cnLabel.mas_bottom).offset(10 * HEI);
        make.width.mas_equalTo(self.image_urlImageView.frame.size.width);
        make.height.mas_equalTo(20 * HEI);
        
        
    }];
    self.name_enLabel.textColor = [UIColor whiteColor];

    
    
    // 图片数量
    self.poi_countLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.poi_countLabel];
    
    [self.poi_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30 * WID);
        make.top.mas_equalTo(self.image_urlImageView.frame.size.height - 30 * HEI);
        make.width.mas_equalTo(100 * WID);
        make.height.mas_equalTo(20 * HEI);
        
    }];
    self.poi_countLabel.backgroundColor = [UIColor blackColor];
    self.poi_countLabel.textAlignment = NSTextAlignmentCenter;
    self.poi_countLabel.font = [UIFont boldSystemFontOfSize:13];
    self.poi_countLabel.textColor = [UIColor whiteColor];
    self.poi_countLabel.alpha = 0.5;
    // 裁掉边框
    self.poi_countLabel.layer.masksToBounds = YES;
    // 设置椭圆形
    self.poi_countLabel.layer.cornerRadius = 10 * WID;
    
    
}
-(void)setForeignModel:(ForeignModel *)foreignModel{

    self.name_zh_cnLabel.text = foreignModel.name_zh_cn;
    self.name_enLabel.text = foreignModel.name_en;
    
    NSString *count = [NSString stringWithFormat:@"旅行地 %@", foreignModel.poi_count];
    self.poi_countLabel.text = count;
    
    
    [self.image_urlImageView sd_setImageWithURL:[NSURL URLWithString:foreignModel.image_url] placeholderImage:[UIImage imageNamed:@"loading.jpg"]];
    
}

@end
